package dome1;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: wx
 * Date: 2023-09-04
 * Time: 23:35
 */


class Money implements Cloneable {
   public double m = 19.0;

    @Override
    protected Object clone() throws CloneNotSupportedException {
        return super.clone();
    }
}

class Person {
    public String name;
    public int age;

    Money money = new Money();
    public Person(String name, int age) {
        this.name = name;
        this.age = age;

    }

    @Override
    public String toString() {
        return "Person{" +
                "name='" + name + '\'' +
                ", age=" + age +
                '}';
    }

    @Override
    protected Object clone() throws CloneNotSupportedException {
        //在这里只克隆了person，斌没有进行mone的克隆，怎么实现克隆呢？
        return super.clone();
    }
}

public class Test {
    public static void main(String[] args) throws CloneNotSupportedException {
        Person person1 = new Person("huana", 12);
        Person person2 = (Person) person1.clone();//克隆方法

        System.out.println(person1.money.m);
        System.out.println(person2.money.m);
        System.out.println("==============================================");
        person1.money.m = 20.99;
        System.out.println("person1"+person1.money.m);
        System.out.println("person2"+person2.money.m);

    }
    public static void main1(String[] args) throws CloneNotSupportedException {
        Person person1 = new Person("huana", 12);
        Person person2 = (Person) person1.clone();//克隆方法
    }
}

